package com.tledu.zyf.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserNameFilter extends HttpFilter {
	// String username;
	//
	// @Override
	// public void init(FilterConfig filterConfig) throws ServletException {
	// username = filterConfig.getInitParameter("username");
	// }
	@Override
	public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		String username = getFilterCofing().getInitParameter("username");
		String name = request.getParameter("username");
		if (username.equals(name)) {
			chain.doFilter(request, response);
		} else {
			// if (response instanceof HttpServletResponse) {
			// HttpServletResponse hsr = (HttpServletResponse)response;
			// hsr.sendRedirect("");
			// }
			request.setAttribute("msg", "用户名不正确");
			request.getRequestDispatcher(".login.jsp").forward(request, response);
		}
	}
}
